package com.woniuxy.exam.common.config;

import com.woniuxy.exam.dto.OrdersDto;
import com.woniuxy.exam.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class InitRunner implements CommandLineRunner{
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private IOrdersService ordersService;

    @Override
    public void run(String... args) throws Exception {
        redisTemplate.delete("orderList");
        List<OrdersDto> ordersDtos = ordersService.queryALL();
        redisTemplate.opsForList().leftPushAll("orderList", ordersDtos);
    }
}
